package com.project.controller;

import com.project.bean.PrimaryPostBean;
import com.project.bean.ReplyBean;
import com.project.bean.UserBean;
import com.project.service.IReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("reply")
public class ReplyController {
    @Autowired
    private IReplyService service;

    @RequestMapping("/add")
    @ResponseBody
    public String add(ReplyBean reply, int primaryId, HttpServletRequest request){
        if(reply.getContent() == null || reply.getContent().length() == 0){
            return "no";
        }
        PrimaryPostBean primary = new PrimaryPostBean();
        primary.setId(primaryId);
        reply.setPrimary(primary);

        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        reply.setUser(user);

        service.add(reply);
        return "ok";
    }

}
